package com.qs.service.impl;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qs.pojo.entity.ExceLog;
import com.qs.mapper.ExceLogMapper;
import com.qs.pojo.entity.OperLog;
import com.qs.service.IExceLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 异常信息日志记录表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-01-04
 */
@Service
public class ExceLogServiceImpl extends ServiceImpl<ExceLogMapper, ExceLog> implements IExceLogService {
    @Override
    public Map<String, Object> getExceptionList(Integer pageNo, Integer pageSize) {
        Page<ExceLog> pageInfo = new Page<>(pageNo, pageSize);
        QueryWrapper<ExceLog> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        Page<ExceLog> operLogPage = baseMapper.selectPage(pageInfo, wrapper);
        if(null != operLogPage){
            List<ExceLog> operLogList = operLogPage.getRecords();
            if(!CollectionUtils.isEmpty(operLogList)){
                operLogList.stream().forEach(item -> {
                    item.setTime(LocalDateTimeUtil.format(LocalDateTimeUtil.parse(item.getCreateTime().toString()), DatePattern.NORM_DATETIME_MINUTE_PATTERN));
                    item.setKey(item.getId());
                });
                Map<String,Object> map = new HashMap<String,Object>();
                map.put("data",operLogList);
                map.put("total",operLogPage.getTotal());
                return map;
            }
            return null;
        }
        return null;
    }
}
